package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaListaLinea extends javax.swing.JFrame {
	private JPanel pnLinea;
	private JButton btEliminar;
	private JScrollPane scpLinea;
	private JTable tbLineaL;
	private JLabel lblImagen;
	private JButton btIncluir;
	private JLabel jLabel1;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	
	public VentanaListaLinea() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			{
				pnLinea = new JPanel();
				getContentPane().add(pnLinea, BorderLayout.CENTER);
				pnLinea.setLayout(null);
				pnLinea.setBackground(new java.awt.Color(255,255,255));
				pnLinea.setPreferredSize(new java.awt.Dimension(572, 383));
				{
					jLabel1 = new JLabel();
					pnLinea.add(jLabel1);
					jLabel1.setText("Lista de lineas");
					jLabel1.setBounds(194, 36, 236, 27);
					jLabel1.setFont(new java.awt.Font("Bitstream Charter",0,20));
				}
				{
					btIncluir = new JButton();
					pnLinea.add(btIncluir);
					btIncluir.setBounds(144, 318, 93, 31);
					btIncluir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Incluir2.jpg")));
					btIncluir.setRolloverIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Incluir.jpg")));
					btIncluir.setActionCommand("Incluir");
					btIncluir.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				}
				{
					btEliminar = new JButton();
					pnLinea.add(btEliminar);
					btEliminar.setBounds(279, 318, 93, 31);
					btEliminar.setActionCommand("Eliminar");
					btEliminar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Eliminar2.jpg")));
					btEliminar.setRolloverIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Eliminar.jpg")));
					btEliminar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				}
				{
					scpLinea = new JScrollPane();
					pnLinea.add(scpLinea);
					scpLinea.setBounds(76, 84, 455, 204);
					{
						DefaultTableModel tbLineaLModel = 
								new DefaultTableModel(
										new String[][] {  },
										new String[] { "Numero de linea", "Nombre" });
						tbLineaL = new JTable();
						scpLinea.setViewportView(tbLineaL);
						tbLineaL.setModel(tbLineaLModel);
					}
				}
				{
					lblImagen = new JLabel();
					pnLinea.add(lblImagen);
					lblImagen.setBounds(0, 25, 50, 387);
					lblImagen.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/fondo7.jpg")));
				}
			}
			pack();
			this.setSize(586, 436);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	public void agregarListener(ActionListener accion) {

		btEliminar.addActionListener(accion);
		btIncluir.addActionListener(accion);
	
	}

	

	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public int getCantidadFilasTbLinea() {
		return this.tbLineaL.getRowCount();
	}

	public void agregarFilaLinea(Vector<String> datoLinea) {
		DefaultTableModel modelop = (DefaultTableModel) this.tbLineaL.getModel();

		modelop.addRow(datoLinea);
		

	}
	
   public void eliminarFilaSeleccionada(int i){
		
		DefaultTableModel modelo = (DefaultTableModel) this.tbLineaL.getModel();

		modelo.removeRow(i);
		
	}
public int getFilaSeleccionada(){
		
		return this.tbLineaL.getSelectedRow();
	}

  public int numeroFilasSeleccionadas() {
	return tbLineaL.getSelectedRowCount();
  }

public String obtenerCodigoProductoFilaSeleccionada() {
	int fila = tbLineaL.getSelectedRow();
	String codigoProducto = (String) tbLineaL.getModel().getValueAt(fila,
			0);
	return codigoProducto;
}
	
	//public void agregarProducto(String infProducto) {
		//DefaultTableModel modeloTabla = (DefaultTableModel) jTProducto.getModel();
		//modeloTabla.addTableModelListener(jTProducto);
	//}
}


